const obj = {
  foo: {
    bar: 'bar'
  },
  baz: 'baz',
  arr: [1, 2, 3]
}

const handler = {
  get(target, key) {
    console.log('收集依赖 >>> ', key)
    if (typeof target[key] === 'object' && target[key] !== null) {
      return new Proxy(target[key], handler)
    }
    return Reflect.get(target, key)
  },
  set(target, key, value) {
    const oldValue = target[key]

    if (!oldValue) {
      console.log('新增属性')
    } else if (oldValue !== value) {
      console.log('修改属性')
    }
    // console.log('触发更新 >>> ', key)
    return Reflect.set(target, key, value)
  }
}

const proxy = new Proxy(obj, handler)

// proxy.foo.bar = 'barrrrr'

// proxy.arr.push(123)
proxy.arr[1] = 222
